package com.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.model.auto.*;
import com.model.auto.vo.GetSchoolVo;
import com.service.*;
import com.util.ProbabilityUtils;
import com.util.R;
import com.util.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.stream.Collectors;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author astupidcoder
 * @since 2022-09-14
 */
@RestController
@RequestMapping("/school")
public class SchoolController{
    @Autowired
    private ISchoolService schoolService;
    @Autowired
    private IMajorService majorService;
    @Autowired
    private IMajorCategoryInfoService majorCategoryInfoService;
    @Autowired
    private ISysDictService sysDictService;
    @Autowired
    private ISchoolLabelService schoolLabelService;
    @Autowired
    private IStudentService studentService;

    private Logger logger = LoggerFactory.getLogger(SchoolController.class);

    @PostMapping("/getStuSchoolInformation")
    public R getStuSchoolInformation(@RequestBody GetSchoolVo getSchoolVo) {
        List<String> majorCodeList = new ArrayList<String>();
        List<Major> majorsList = majorService.list(new LambdaQueryWrapper<Major>()
                //只模糊匹配右边的内容，这样可以命重索引
                .likeRight(!StringUtil.isEmpty(getSchoolVo.getMajor1()), Major::getMajorName, getSchoolVo.getMajor1())
                .eq(Major::getType, getSchoolVo.getMajorType())
                .eq(Major::getBatch,getSchoolVo.getBatch())
                .select(Major::getCode,Major::getId)
        );
        //将list 转换Map对象，优化双层for循环嵌套数据匹配。
        Map<Long ,Major> majorMap = new HashMap<>();
        majorsList.stream().forEach(tmp->{
            majorMap.put(tmp.getId(),tmp);
            majorCodeList.add(tmp.getCode());
        });


        List<String> Hierarchyscode = new ArrayList<String>();
        List<String> qualificationscode = new ArrayList<String>();
        if (!StringUtil.isEmpty(getSchoolVo.getHierarchys())) {
            List<SchoolLabel> Hierarchyss = schoolLabelService.getcollegeLevel(getSchoolVo.getHierarchys());
            if (Hierarchyss.size() > 0) {
                Hierarchyss.forEach(i -> Hierarchyscode.add(i.getCode()));
            }
        }
        if (!StringUtil.isEmpty(getSchoolVo.getQualifications())) {
            List<SchoolLabel> qualificationss = schoolLabelService.getqualifications(getSchoolVo.getQualifications());
            if (qualificationss.size() > 0) {
                qualificationss.forEach(i -> qualificationscode.add(i.getCode()));
            }
        }
        String city=getSchoolVo.getCity().toString();
        List<SchoolLabel> schoolLabels;
        List<Object> citys= Arrays.asList("陕西省","安徽省","北京市","重庆市","福建省","广东省","广西","甘肃省","贵州省","河北省",
                "河南省","海南省","湖北省","湖南省","黑龙江省","吉林省","江苏省","江西省","辽宁省","内蒙古","宁夏","青海省","上海市",
                "四川省","山东省","山西省","天津市","西藏","新疆","云南省","浙江省");
        logger.info("城市数据集合：{}",city);
        if (!StringUtil.isEmpty(getSchoolVo.getCity())&&city.equals("[其他]")){
                         schoolLabels = schoolLabelService.list(new LambdaQueryWrapper<SchoolLabel>()
                    .in(!StringUtil.isEmpty(Hierarchyscode), SchoolLabel::getCode, Hierarchyscode)
                    .in(!StringUtil.isEmpty(qualificationscode), SchoolLabel::getCode, qualificationscode)
                    .notIn(SchoolLabel::getCity, citys)
                    .in(!StringUtil.isEmpty(getSchoolVo.getNature()), SchoolLabel::getNature, getSchoolVo.getNature())
                    .select(SchoolLabel::getCode)
            );
        }else{
                         schoolLabels = schoolLabelService.list(new LambdaQueryWrapper<SchoolLabel>()
                    .in(!StringUtil.isEmpty(Hierarchyscode), SchoolLabel::getCode, Hierarchyscode)
                    .in(!StringUtil.isEmpty(qualificationscode), SchoolLabel::getCode, qualificationscode)
                    .in(!StringUtil.isEmpty(getSchoolVo.getCity()), SchoolLabel::getCity, getSchoolVo.getCity())
                    .in(!StringUtil.isEmpty(getSchoolVo.getNature()), SchoolLabel::getNature, getSchoolVo.getNature())
                    .select(SchoolLabel::getCode)
            );
        }

        List<String> codeList = schoolLabels.stream().map(SchoolLabel::getCode).collect(Collectors.toList());
//        System.out.println("这个集合:" + codeList.size());
        logger.info("codeList：{}",codeList.size());
        if (codeList.size() <= 0) {
            PageInfo<School> pageInfos = PageHelper.startPage(getSchoolVo.getPageNum(), getSchoolVo.getPageSize()).doSelectPageInfo(() -> {
            });
            return R.ok(pageInfos);
        }
        String schoolType=getSchoolVo.getType().toString();
        PageInfo<School> pageInfo;
        List<Object> schoolTypes=Arrays.asList("综合","工科","财经","农业","林业","医药","师范","体育","政法","民族","语言","军事"
                ,"艺术");
        if (!StringUtil.isEmpty(getSchoolVo.getType())&&schoolType.equals("[其他]")){
                         pageInfo = PageHelper.startPage(getSchoolVo.getPageNum(), getSchoolVo.getPageSize()).doSelectPageInfo(() -> {
                schoolService.list(new LambdaQueryWrapper<School>()
                        .in(!StringUtil.isEmpty(majorCodeList), School::getCode, majorCodeList)
                        .in(!StringUtil.isEmpty(codeList), School::getCode, codeList)
                        .notIn(School::getSchoolType, schoolTypes)
                        .like(!StringUtil.isEmpty(getSchoolVo.getSchool()), School::getSchoolName, getSchoolVo.getSchool())
                        .eq(!StringUtil.isEmpty(getSchoolVo.getBatch()), School::getBatch, getSchoolVo.getBatch())
                        .eq(getSchoolVo.getType()!=null, School::getType, getSchoolVo.getMajorType())
                        .orderByAsc(School::getProposedwc)
                );
            });
        }else{
                         pageInfo = PageHelper.startPage(getSchoolVo.getPageNum(), getSchoolVo.getPageSize()).doSelectPageInfo(() -> {
                schoolService.list(new LambdaQueryWrapper<School>()
                        .in(!StringUtil.isEmpty(majorCodeList), School::getCode, majorCodeList)
                        .in(!StringUtil.isEmpty(codeList), School::getCode, codeList)
                        .in(!StringUtil.isEmpty(getSchoolVo.getType()), School::getSchoolType, getSchoolVo.getType())
                        .like(!StringUtil.isEmpty(getSchoolVo.getSchool()), School::getSchoolName, getSchoolVo.getSchool())
                        .eq(!StringUtil.isEmpty(getSchoolVo.getBatch()), School::getBatch, getSchoolVo.getBatch())
                        .eq(getSchoolVo.getMajorType()!=null, School::getType, getSchoolVo.getMajorType())
                        .orderByAsc(School::getProposedwc)
                );
            });
        }

        List<School> schools = pageInfo.getList();
        //统计分页后的学校编号
        ArrayList<Object> endCodeList = new ArrayList<>();
        schools.forEach(i -> endCodeList.add(i.getCode()));
        //根据学校编号查出专业
        List<Major> list = endCodeList.size() == 0 ? new ArrayList<>() :
                majorService.list(new LambdaQueryWrapper<Major>()
                        .in(Major::getCode, endCodeList)
                        .eq(!StringUtil.isEmpty(getSchoolVo.getBatch()), Major::getBatch, getSchoolVo.getBatch())
                        .eq(getSchoolVo.getMajorType()!=null, Major::getType, getSchoolVo.getMajorType())
                );
        //自家加注释
        Map<String,List<Major>> majorMapList = list.stream().collect(Collectors.groupingBy(Major::getCode));

        if (!StringUtil.isEmpty(getSchoolVo.getMajor1())){
            list.forEach(l->{
                Major majorTmp = majorMap.get(l.getId());
                if(!Objects.isNull(majorTmp)){
                    l.setColor("red");

                }

//                majors.forEach(m->{
//                    if (l.getId().equals(m.getId())){
//                        l.setColor("red");
//                    }
//                });
            });
        }

        System.out.println("排序后的学校:" + schools.size());
        for (School j : schools) {
            List<Major> majorList = majorMapList.get(j.getCode());
//            for (Major i : list) {
//                if (i.getCode().equals(j.getCode())) {
//                    majorList.add(i);
//                }
//            }
            j.setChildren(majorList);
        }
        pageInfo.setList(schools);
        return R.ok(pageInfo);
    }

    @PostMapping("getSchoolInformations")
    public R getSchoolInformations(@RequestBody GetSchoolVo getSchoolVo){
        List<School> schools=schoolService.list(new LambdaQueryWrapper<School>()
                .eq(School::getBatch,getSchoolVo.getBatch())
                .eq(getSchoolVo.getMajorType()!=null,School::getType,getSchoolVo.getMajorType())
                .in(!ObjectUtils.isEmpty(getSchoolVo.getRecruitType()), School::getRecruitType, getSchoolVo.getRecruitType())
                .orderByAsc(School::getProposedwc)
        );
        Boolean isProbability = false;
        Integer precedence = null;
        //如果stuId不为null，计算录取概率
        if(Objects.nonNull(getSchoolVo.getStuId())){
            Student student = studentService.getById(getSchoolVo.getStuId());
            if(Objects.nonNull(student) && !StringUtil.isEmpty(student.getPrecedence()) && StringUtil.isNumeric(student.getPrecedence())){
                isProbability = true;
                precedence = Integer.valueOf(student.getPrecedence());
            }
        }
        for(School school:schools){
            if(isProbability){
                getSchoolProbability(school, precedence, getSchoolVo.getBatch());
            }
        }
        return R.ok(schools);
    }

    @PostMapping("/getSchoolInformation")
    public R getSchoolInformation(@RequestBody GetSchoolVo getSchoolVo) {
        List<Integer> schoolIdList = new ArrayList<>();

        List<School> relust=schoolService.list(new LambdaQueryWrapper<School>()
                .eq(!StringUtil.isEmpty(getSchoolVo.getBatch()), School::getBatch, getSchoolVo.getBatch())
                .eq(getSchoolVo.getMajorType()!=null, School::getType, getSchoolVo.getMajorType())
                .in(!ObjectUtils.isEmpty(getSchoolVo.getRecruitType()), School::getRecruitType, getSchoolVo.getRecruitType())
                .orderByAsc(School::getProposedwc)
        );

        Boolean isProbability = false;
        Integer precedence = null;
        //如果stuId不为null，计算录取概率
        if(Objects.nonNull(getSchoolVo.getStuId())){
            Student student = studentService.getById(getSchoolVo.getStuId());
            if(Objects.nonNull(student) && !StringUtil.isEmpty(student.getPrecedence()) && StringUtil.isNumeric(student.getPrecedence())){
                isProbability = true;
                precedence = Integer.valueOf(student.getPrecedence());
            }
        }

        if(!StringUtil.isEmpty(getSchoolVo.getMajor1()) || !StringUtil.isEmpty(getSchoolVo.getMajor2()) || !StringUtil.isEmpty(getSchoolVo.getMajor3())){
            schoolIdList = majorService.getSchoolIdByMajorName(getSchoolVo.getMajorType(), getSchoolVo.getBatch(), getSchoolVo.getMajor1(), getSchoolVo.getMajor2(), getSchoolVo.getMajor3());
            if(ObjectUtils.isEmpty(schoolIdList)){
                for(School school:relust){
                    if(isProbability){
                        getSchoolProbability(school, precedence, getSchoolVo.getBatch());
                    }
                }
                return R.ok(relust);
            }
        }

        List<String> Hierarchyscode = new ArrayList<String>();
        List<String> qualificationscode = new ArrayList<String>();
        if (!StringUtil.isEmpty(getSchoolVo.getHierarchys())) {
            List<SchoolLabel> Hierarchyss = schoolLabelService.getcollegeLevel(getSchoolVo.getHierarchys());
            if (Hierarchyss.size() > 0) {
                Hierarchyss.forEach(i -> Hierarchyscode.add(i.getCode()));
            }
        }
        if (!StringUtil.isEmpty(getSchoolVo.getQualifications())) {
            List<SchoolLabel> qualificationss = schoolLabelService.getqualifications(getSchoolVo.getQualifications());
            if (qualificationss.size() > 0) {
                qualificationss.forEach(i -> qualificationscode.add(i.getCode()));
            }
        }
        String city=getSchoolVo.getCity().toString();
        List<SchoolLabel> schoolLabels;
        List<Object> citys= Arrays.asList("陕西省","安徽省","北京市","重庆市","福建省","广东省","广西","甘肃省","贵州省","河北省",
                "河南省","海南省","湖北省","湖南省","黑龙江省","吉林省","江苏省","江西省","辽宁省","内蒙古","宁夏","青海省","上海市",
                "四川省","山东省","山西省","天津市","西藏","新疆","云南省","浙江省");

        if (!StringUtil.isEmpty(getSchoolVo.getCity()) && city.equals("[其他]")) {
            schoolLabels = schoolLabelService.list(new LambdaQueryWrapper<SchoolLabel>()
                    .in(!StringUtil.isEmpty(Hierarchyscode), SchoolLabel::getCode, Hierarchyscode)
                    .in(!StringUtil.isEmpty(qualificationscode), SchoolLabel::getCode, qualificationscode)
                    .notIn(SchoolLabel::getCity, citys)
                    .in(!StringUtil.isEmpty(getSchoolVo.getNature()), SchoolLabel::getNature, getSchoolVo.getNature())
                    .select(SchoolLabel::getCode)
            );
        } else {
            schoolLabels = schoolLabelService.list(new LambdaQueryWrapper<SchoolLabel>()
                    .in(!StringUtil.isEmpty(Hierarchyscode), SchoolLabel::getCode, Hierarchyscode)
                    .in(!StringUtil.isEmpty(qualificationscode), SchoolLabel::getCode, qualificationscode)
                    .in(!StringUtil.isEmpty(getSchoolVo.getCity()), SchoolLabel::getCity, getSchoolVo.getCity())
                    .in(!StringUtil.isEmpty(getSchoolVo.getNature()), SchoolLabel::getNature, getSchoolVo.getNature())
                    .select(SchoolLabel::getCode)
            );
        }
        List<String> codeList = schoolLabels.stream().map(SchoolLabel::getCode).collect(Collectors.toList());
        if (codeList.size() <= 0) {
            PageInfo<School> pageInfos = PageHelper.startPage(getSchoolVo.getPageNum(), getSchoolVo.getPageSize()).doSelectPageInfo(() -> {
            });
            for(School school:relust){
                if(isProbability){
                    getSchoolProbability(school, precedence, getSchoolVo.getBatch());
                }
            }
            return R.ok(pageInfos);
        }
        String schoolType=getSchoolVo.getType().toString();
        List<School> pageInfo;
        List<Object> schoolTypes=Arrays.asList("综合","工科","财经","农业","林业","医药","师范","体育","政法","民族","语言"
                ,"艺术");
        if (!StringUtil.isEmpty(getSchoolVo.getType())&&schoolType.equals("[其他]")){
                 pageInfo = schoolService.list(new LambdaQueryWrapper<School>()
                    .in(!CollectionUtils.isEmpty(schoolIdList), School::getId, schoolIdList)
                    .in(!StringUtil.isEmpty(codeList), School::getCode, codeList)
                    .notIn(School::getSchoolType,schoolTypes)
//                    .like(!StringUtil.isEmpty(getSchoolVo.getSchool()), School::getSchoolName, getSchoolVo.getSchool())
                    .eq(!StringUtil.isEmpty(getSchoolVo.getBatch()), School::getBatch, getSchoolVo.getBatch())
                    .eq(getSchoolVo.getMajorType()!=null, School::getType, getSchoolVo.getMajorType())
            );
        }else{
                pageInfo = schoolService.list(new LambdaQueryWrapper<School>()
                    .in(!CollectionUtils.isEmpty(schoolIdList), School::getId, schoolIdList)
                    .in(!StringUtil.isEmpty(codeList), School::getCode, codeList)
                    .in(!StringUtil.isEmpty(getSchoolVo.getType()), School::getSchoolType, getSchoolVo.getType())
//                    .like(!StringUtil.isEmpty(getSchoolVo.getSchool()), School::getSchoolName, getSchoolVo.getSchool())
                    .eq(!StringUtil.isEmpty(getSchoolVo.getBatch()), School::getBatch, getSchoolVo.getBatch())
                    .eq(getSchoolVo.getMajorType()!=null, School::getType, getSchoolVo.getMajorType())

            );
        }

        for(School school:relust){
            pageInfo.forEach(p->{
                if (p.getId().equals(school.getId())){
                    school.setColor(1);
                }
            });
            if(isProbability){
                getSchoolProbability(school, precedence, getSchoolVo.getBatch());
            }
        }
        return R.ok(relust);
    }

    @PostMapping("/getSchoolMajor")
    public R getSchoolMajor(@RequestBody GetSchoolVo getSchoolVo) {
        Boolean isProbability = false;
        Integer precedence = null;
        //如果stuId不为null，计算录取概率
        if(Objects.nonNull(getSchoolVo.getStuId())){
            Student student = studentService.getById(getSchoolVo.getStuId());
            if(Objects.nonNull(student) && !StringUtil.isEmpty(student.getPrecedence()) && StringUtil.isNumeric(student.getPrecedence())){
                isProbability = true;
                precedence = Integer.valueOf(student.getPrecedence());
            }
        }

        List<Major> list = majorService.list(new LambdaQueryWrapper<Major>()
                .eq(!StringUtil.isEmpty(getSchoolVo.getSchoolCode()), Major::getCode, getSchoolVo.getSchoolCode())
                .eq(Major::getType, getSchoolVo.getMajorType())
                .eq(!StringUtil.isEmpty(getSchoolVo.getBatch()), Major::getBatch, getSchoolVo.getBatch())
                .eq(!StringUtil.isEmpty(getSchoolVo.getSchoolRecruitType()), Major::getRecruitType, getSchoolVo.getSchoolRecruitType())
        );
        if (StringUtils.hasText(getSchoolVo.getMajor1()) || StringUtils.hasText(getSchoolVo.getMajor2()) || StringUtils.hasText(getSchoolVo.getMajor3())) {
            List<Major> limit = majorService.list(new LambdaQueryWrapper<Major>()
                    .and(wrapper ->
                            wrapper.like(!StringUtil.isEmpty(getSchoolVo.getMajor1()), Major::getMajorName, getSchoolVo.getMajor1())
                                    .or().like(!StringUtil.isEmpty(getSchoolVo.getMajor2()), Major::getMajorName, getSchoolVo.getMajor2())
                                    .or().like(!StringUtil.isEmpty(getSchoolVo.getMajor3()), Major::getMajorName, getSchoolVo.getMajor3())
                    )
                    .eq(!StringUtil.isEmpty(getSchoolVo.getSchoolCode()), Major::getCode, getSchoolVo.getSchoolCode())
                    .eq(Major::getType, getSchoolVo.getMajorType())
                    .eq(!StringUtil.isEmpty(getSchoolVo.getBatch()), Major::getBatch, getSchoolVo.getBatch())
                    .select(Major::getId)
            );
            list.forEach(l -> {
                limit.forEach(m -> {
                    if (l.getId().equals(m.getId())) {
                        l.setColor("red");
                    }
                });
            });
        }
        if(isProbability){
            for(Major major:list){
                getMajorProbability(major, precedence, major.getBatch());
            }
        }
        return R.ok(list);
    }

    @GetMapping("/getMajor")
    public R getMajor() {
        List<Major> list = majorService.getMajorNameList();
        List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
        for (Major i : list) {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("value", i.getMajorName());
            result.add(map);
        }
        return R.ok(result);
    }

    //院校查询专业输入框提示
    @GetMapping("/getMajorName")
    public R getMajorName() {
        List<MajorCategoryInfo> list = majorCategoryInfoService.list(new LambdaQueryWrapper<MajorCategoryInfo>()
                .eq(MajorCategoryInfo::getLevel,3)
                .eq(MajorCategoryInfo::getCatType,1)
        );
        List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
        for (MajorCategoryInfo i : list) {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("value", i.getName());
            result.add(map);
        }
        return R.ok(result);
    }

    @PostMapping("/getSchoolName")
    public R getSchoolName(@Param("majorType") String majorType, @Param("batch") String batch) {
        List<School> list = schoolService.list(new LambdaQueryWrapper<School>()
                .eq(!StringUtil.isEmpty(majorType), School::getType, majorType)
                .eq(!StringUtil.isEmpty(batch), School::getBatch, batch));
        List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
        for (School i : list) {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("value", i.getSchoolName());
            result.add(map);
        }
        return R.ok(result);
    }


    @PostMapping("/getStuSchool")
    public R getStuSchool(@RequestBody GetSchoolVo getSchoolVo) {
        List<String> majorCodeList = new ArrayList<String>();
        List<Major> majors = majorService.list(new LambdaQueryWrapper<Major>()
                .like(!StringUtil.isEmpty(getSchoolVo.getMajor1()), Major::getMajorName, getSchoolVo.getMajor1())
                .eq(Major::getType, getSchoolVo.getMajorType())
                .eq(Major::getBatch,getSchoolVo.getBatch())
                .select(Major::getCode,Major::getId)
        );
        if (majors.size() > 0) {
            majors.forEach(i -> majorCodeList.add(i.getCode()));
        }
        List<String> Hierarchyscode = new ArrayList<String>();
        List<String> qualificationscode = new ArrayList<String>();
        if (!StringUtil.isEmpty(getSchoolVo.getHierarchys())) {
            List<SchoolLabel> Hierarchyss = schoolLabelService.getcollegeLevel(getSchoolVo.getHierarchys());
            if (Hierarchyss.size() > 0) {
                Hierarchyss.forEach(i -> Hierarchyscode.add(i.getCode()));
            }
        }
        if (!StringUtil.isEmpty(getSchoolVo.getQualifications())) {
            List<SchoolLabel> qualificationss = schoolLabelService.getqualifications(getSchoolVo.getQualifications());
            if (qualificationss.size() > 0) {
//                System.out.println("这块能进来");
                qualificationss.forEach(i -> qualificationscode.add(i.getCode()));
            }
        }
        String city=getSchoolVo.getCity().toString();
        List<SchoolLabel> schoolLabels;
        List<Object> citys= Arrays.asList("陕西省","安徽省","北京市","重庆市","福建省","广东省","广西","甘肃省","贵州省","河北省",
                "河南省","海南省","湖北省","湖南省","黑龙江省","吉林省","江苏省","江西省","辽宁省","内蒙古","宁夏","青海省","上海市",
                "四川省","山东省","山西省","天津市","西藏","新疆","云南省","浙江省");
        System.out.println("集合"+citys);
        if (!StringUtil.isEmpty(getSchoolVo.getCity())&&city.equals("[其他]")){
                         schoolLabels = schoolLabelService.list(new LambdaQueryWrapper<SchoolLabel>()
                    .notIn(SchoolLabel::getCity, citys)
                    .in(!StringUtil.isEmpty(getSchoolVo.getNature()), SchoolLabel::getNature, getSchoolVo.getNature())
                    .in(!StringUtil.isEmpty(Hierarchyscode), SchoolLabel::getCode, Hierarchyscode)
                    .in(!StringUtil.isEmpty(qualificationscode), SchoolLabel::getCode, qualificationscode)
                    .select(SchoolLabel::getCode)
            );
        }else{
            schoolLabels = schoolLabelService.list(new LambdaQueryWrapper<SchoolLabel>()
                    .in(!StringUtil.isEmpty(getSchoolVo.getCity()), SchoolLabel::getCity, getSchoolVo.getCity())
                    .in(!StringUtil.isEmpty(getSchoolVo.getNature()), SchoolLabel::getNature, getSchoolVo.getNature())
                    .in(!StringUtil.isEmpty(Hierarchyscode), SchoolLabel::getCode, Hierarchyscode)
                    .in(!StringUtil.isEmpty(qualificationscode), SchoolLabel::getCode, qualificationscode)
                    .select(SchoolLabel::getCode)
            );
        }

        List<String> codeList = schoolLabels.stream().map(SchoolLabel::getCode).collect(Collectors.toList());
//        System.out.println("这个集合" + codeList);
        if (!StringUtil.isEmpty(getSchoolVo.getMaxranking()) && !StringUtil.isEmpty(getSchoolVo.getMinranking())) {
            getSchoolVo.setMaxfraction(null);
            getSchoolVo.setMinfraction(null);
        }
        if (codeList.size() <= 0) {
            PageInfo<School> pageInfos = PageHelper.startPage(getSchoolVo.getPageNum(), getSchoolVo.getPageSize()).doSelectPageInfo(() -> {
            });
            return R.ok(pageInfos);
        }
        String schoolType=getSchoolVo.getType().toString();
        PageInfo<School> pageInfo;
        List<Object> schoolTypes=Arrays.asList("综合","工科","财经","农业","林业","医药","师范","体育","政法","民族","语言","军事"
                ,"艺术");
        if (!StringUtil.isEmpty(getSchoolVo.getType())&&schoolType.equals("[其他]")){
                         pageInfo = PageHelper.startPage(getSchoolVo.getPageNum(), getSchoolVo.getPageSize()).doSelectPageInfo(() -> {
                schoolService.list(new LambdaQueryWrapper<School>()
                        .in(!StringUtil.isEmpty(majorCodeList), School::getCode, majorCodeList)
                        .in(!StringUtil.isEmpty(codeList), School::getCode, codeList)
                        .notIn(School::getSchoolType, schoolTypes)
                        .like(!StringUtil.isEmpty(getSchoolVo.getSchool()), School::getSchoolName, getSchoolVo.getSchool())
                        .eq(!StringUtil.isEmpty(getSchoolVo.getBatch()), School::getBatch, getSchoolVo.getBatch())
                        .eq(getSchoolVo.getMajorType()!=null, School::getType, getSchoolVo.getMajorType())
                        .ge(!StringUtil.isEmpty(getSchoolVo.getMinfraction()), School::getProposedScore, getSchoolVo.getMinfraction())
                        .le(!StringUtil.isEmpty(getSchoolVo.getMaxfraction()), School::getProposedScore, getSchoolVo.getMaxfraction())
                        .ge(!StringUtil.isEmpty(getSchoolVo.getMaxranking()), School::getProposedwc, getSchoolVo.getMaxranking())
                        .le(!StringUtil.isEmpty(getSchoolVo.getMinranking()), School::getProposedwc, getSchoolVo.getMinranking())
                        .orderByAsc(School::getProposedwc)
                );
            });
        }else{
            pageInfo = PageHelper.startPage(getSchoolVo.getPageNum(), getSchoolVo.getPageSize()).doSelectPageInfo(() -> {
                schoolService.list(new LambdaQueryWrapper<School>()
                        .in(!StringUtil.isEmpty(majorCodeList), School::getCode, majorCodeList)
                        .in(!StringUtil.isEmpty(codeList), School::getCode, codeList)
                        .in(!StringUtil.isEmpty(getSchoolVo.getType()), School::getSchoolType, getSchoolVo.getType())
                        .like(!StringUtil.isEmpty(getSchoolVo.getSchool()), School::getSchoolName, getSchoolVo.getSchool())
                        .eq(!StringUtil.isEmpty(getSchoolVo.getBatch()), School::getBatch, getSchoolVo.getBatch())
                        .eq(getSchoolVo.getMajorType()!=null, School::getType, getSchoolVo.getMajorType())
                        .ge(!StringUtil.isEmpty(getSchoolVo.getMinfraction()), School::getProposedScore, getSchoolVo.getMinfraction())
                        .le(!StringUtil.isEmpty(getSchoolVo.getMaxfraction()), School::getProposedScore, getSchoolVo.getMaxfraction())
                        .ge(!StringUtil.isEmpty(getSchoolVo.getMaxranking()), School::getProposedwc, getSchoolVo.getMaxranking())
                        .le(!StringUtil.isEmpty(getSchoolVo.getMinranking()), School::getProposedwc, getSchoolVo.getMinranking())
                        .orderByAsc(School::getProposedwc)
                );
            });
        }

        List<School> schools = pageInfo.getList();
        //统计分页后的学校编号
        ArrayList<Object> endCodeList = new ArrayList<>();
        schools.forEach(i -> endCodeList.add(i.getCode()));
        //根据学校编号查出专业
        List<Major> list = endCodeList.size() == 0 ? new ArrayList<>() :
                majorService.list(new LambdaQueryWrapper<Major>()
                        .in(Major::getCode, endCodeList)
                        .eq(!StringUtil.isEmpty(getSchoolVo.getBatch()), Major::getBatch, getSchoolVo.getBatch())
                        .eq(getSchoolVo.getMajorType()!=null, Major::getType, getSchoolVo.getMajorType())
                );
        if(!StringUtil.isEmpty(getSchoolVo.getMajor1())){
            list.forEach(l->{
                majors.forEach(m->{
                    if (l.getId().equals(m.getId())){
                        l.setColor("red");
                    }
                });
            });
        }
        for (School j : schools) {
            ArrayList<Major> majorList = new ArrayList<>();
            for (Major i : list) {
                if (i.getCode().equals(j.getCode())) {
                    majorList.add(i);
                }
            }
            j.setChildren(majorList);
        }
        if (!getSchoolVo.getBatch().equals("提前批A段") && !getSchoolVo.getBatch().equals("提前批B段") && !getSchoolVo.getBatch().equals("提前批C段") && !getSchoolVo.getBatch().equals("提前批专科") && !getSchoolVo.getBatch().equals("一批特殊") && !getSchoolVo.getBatch().equals("二批特殊")) {
            if (!StringUtil.isEmpty(getSchoolVo.getRanking())) {
                for (School s : schools) {
                    if (s.getProposedwc() <= (Integer.parseInt(getSchoolVo.getRanking()) * 1.1)) {
                        s.setSprint("冲");
                    } else {
                        if (getSchoolVo.getBatch().equals("本科二批")) {
                            if ((s.getProposedwc() > (Integer.parseInt(getSchoolVo.getRanking()) * 1.1)) && (s.getProposedwc() <= (Integer.parseInt(getSchoolVo.getRanking()) * 1.4))) {
                                s.setSprint("稳");
                            } else if (s.getProposedwc() > (Integer.parseInt(getSchoolVo.getRanking()) * 1.4)) {
                                s.setSprint("保");
                            }
                        } else {
                            if ((s.getProposedwc() > (Integer.parseInt(getSchoolVo.getRanking()) * 1.1)) && (s.getProposedwc() <= (Integer.parseInt(getSchoolVo.getRanking()) * 1.6))) {
                                s.setSprint("稳");
                            } else if (s.getProposedwc() > (Integer.parseInt(getSchoolVo.getRanking()) * 1.6)) {
                                s.setSprint("保");
                            }
                        }
                    }
                }
            } else if (StringUtil.isEmpty(getSchoolVo.getRanking())&&!StringUtil.isEmpty(getSchoolVo.getFraction())) {
                String ranking = "";
                if (getSchoolVo.getMajorType() == 1) {
                    List<SysDict> km = sysDictService.list(new LambdaQueryWrapper<SysDict>().
                            eq(SysDict::getDictType, "rankingli"));
                    for (SysDict sysDict : km) {
                        if (sysDict.getDictName().equals(getSchoolVo.getFraction())) {
                            ranking = String.valueOf(sysDict.getDictValue());
                        }
                    }
                } else if (getSchoolVo.getMajorType() == 2) {
                    List<SysDict> km = sysDictService.list(new LambdaQueryWrapper<SysDict>().
                            eq(SysDict::getDictType, "rankingwen"));
                    for (SysDict sysDict : km) {
                        if (sysDict.getDictName().equals(getSchoolVo.getFraction())) {
                            ranking = String.valueOf(sysDict.getDictValue());
                        }
                    }
                }
//                System.out.println("转换后的位次是" + ranking);
                for (School s : schools) {
                    if (s.getProposedwc() <= (Integer.parseInt(ranking) * 1.1)) {
                        s.setSprint("冲");
                    } else {
                        if (getSchoolVo.getBatch().equals("本科二批")) {
                            if ((s.getProposedwc() > (Integer.parseInt(ranking) * 1.1)) && (s.getProposedwc() <= (Integer.parseInt(ranking) * 1.4))) {
                                s.setSprint("稳");
                            } else if (s.getProposedwc() > (Integer.parseInt(ranking) * 1.4)) {
                                s.setSprint("保");
                            }
                        } else {
                            if ((s.getProposedwc() > (Integer.parseInt(ranking) * 1.1)) && (s.getProposedwc() <= (Integer.parseInt(ranking) * 1.6))) {
                                s.setSprint("稳");
                            } else if (s.getProposedwc() > (Integer.parseInt(ranking) * 1.6)) {
                                s.setSprint("保");
                            }
                        }
                    }
                }
            }
        }
        pageInfo.setList(schools);
        return R.ok(pageInfo);
    }


    @PostMapping("/getSchool")
    public R getSchool(@RequestBody GetSchoolVo getSchoolVo) {
        List<String> majorCodeList = new ArrayList<String>();
        List<Major> majors1 = majorService.list(new LambdaQueryWrapper<Major>()
                .like(!StringUtil.isEmpty(getSchoolVo.getMajor1()), Major::getMajorName, getSchoolVo.getMajor1())
                .eq(Major::getType, getSchoolVo.getMajorType())
                .select(Major::getCode,Major::getId)
                .eq(Major::getBatch,getSchoolVo.getBatch())
        );
        List<Major> majors2 = majorService.list(new LambdaQueryWrapper<Major>()
                .like(!StringUtil.isEmpty(getSchoolVo.getMajor2()), Major::getMajorName, getSchoolVo.getMajor2())
                .eq(Major::getType, getSchoolVo.getMajorType())
                .select(Major::getCode,Major::getId)
                .eq(Major::getBatch,getSchoolVo.getBatch())
        );
        List<Major> majors3 = majorService.list(new LambdaQueryWrapper<Major>()
                .like(!StringUtil.isEmpty(getSchoolVo.getMajor3()), Major::getMajorName, getSchoolVo.getMajor3())
                .eq(Major::getType, getSchoolVo.getMajorType())
                .select(Major::getCode,Major::getId)
                .eq(Major::getBatch,getSchoolVo.getBatch())
        );
        if (!StringUtil.isEmpty(getSchoolVo.getMajor1())||!StringUtil.isEmpty(getSchoolVo.getMajor2())||!StringUtil.isEmpty(getSchoolVo.getMajor1())){
            if (StringUtil.isEmpty(getSchoolVo.getMajor1())){
                majors1=new ArrayList<Major>();
            }
            if (StringUtil.isEmpty(getSchoolVo.getMajor2())){
                majors2=new ArrayList<Major>();
            }
            if (StringUtil.isEmpty(getSchoolVo.getMajor3())){
                majors3=new ArrayList<Major>();
            }
        }
        if (majors1.size() > 0||majors2.size()>0||majors3.size()>0) {
            if (majors1.size() > 0){
                majors1.forEach(i -> majorCodeList.add(i.getCode()));
            }
            if (majors2.size() > 0){
                majors2.forEach(i -> majorCodeList.add(i.getCode()));
            }
            if (majors3.size() > 0){
                majors3.forEach(i -> majorCodeList.add(i.getCode()));
            }
        }else{
            List<School> nullSchool=new ArrayList<>();
            return R.ok(nullSchool);
        }
        List<String> Hierarchyscode = new ArrayList<String>();
        List<String> qualificationscode = new ArrayList<String>();
        if (!StringUtil.isEmpty(getSchoolVo.getHierarchys())) {
            List<SchoolLabel> Hierarchyss = schoolLabelService.getcollegeLevel(getSchoolVo.getHierarchys());
            if (Hierarchyss.size() > 0) {
                Hierarchyss.forEach(i -> Hierarchyscode.add(i.getCode()));
            }
        }
        if (!StringUtil.isEmpty(getSchoolVo.getQualifications())) {
            List<SchoolLabel> qualificationss = schoolLabelService.getqualifications(getSchoolVo.getQualifications());
            if (qualificationss.size() > 0) {
                qualificationss.forEach(i -> qualificationscode.add(i.getCode()));
            }
        }
        String city=getSchoolVo.getCity().toString();
        List<SchoolLabel> schoolLabels;
        List<Object> citys= Arrays.asList("陕西省","安徽省","北京市","重庆市","福建省","广东省","广西","甘肃省","贵州省","河北省",
                "河南省","海南省","湖北省","湖南省","黑龙江省","吉林省","江苏省","江西省","辽宁省","内蒙古","宁夏","青海省","上海市",
                "四川省","山东省","山西省","天津市","西藏","新疆","云南省","浙江省");
//        System.out.println("集合"+citys);
        if (!StringUtil.isEmpty(getSchoolVo.getCity())&&city.equals("[其他]")){
                         schoolLabels = schoolLabelService.list(new LambdaQueryWrapper<SchoolLabel>()
                    .notIn(SchoolLabel::getCity, citys)
                    .in(!StringUtil.isEmpty(getSchoolVo.getNature()), SchoolLabel::getNature, getSchoolVo.getNature())
                    .in(!StringUtil.isEmpty(Hierarchyscode), SchoolLabel::getCode, Hierarchyscode)
                    .in(!StringUtil.isEmpty(qualificationscode), SchoolLabel::getCode, qualificationscode)
                    .select(SchoolLabel::getCode)
            );
        }else{
                         schoolLabels = schoolLabelService.list(new LambdaQueryWrapper<SchoolLabel>()
                    .in(!StringUtil.isEmpty(getSchoolVo.getCity()), SchoolLabel::getCity, getSchoolVo.getCity())
                    .in(!StringUtil.isEmpty(getSchoolVo.getNature()), SchoolLabel::getNature, getSchoolVo.getNature())
                    .in(!StringUtil.isEmpty(Hierarchyscode), SchoolLabel::getCode, Hierarchyscode)
                    .in(!StringUtil.isEmpty(qualificationscode), SchoolLabel::getCode, qualificationscode)
                    .select(SchoolLabel::getCode)
                         );
        }

        List<String> codeList = schoolLabels.stream().map(SchoolLabel::getCode).collect(Collectors.toList());
        if (!StringUtil.isEmpty(getSchoolVo.getMaxranking()) && !StringUtil.isEmpty(getSchoolVo.getMinranking())) {
            getSchoolVo.setMaxfraction(null);
            getSchoolVo.setMinfraction(null);
        }
        if (codeList.size() <= 0) {
            PageInfo<School> pageInfos = PageHelper.startPage(getSchoolVo.getPageNum(), getSchoolVo.getPageSize()).doSelectPageInfo(() -> {
            });
            return R.ok(pageInfos);
        }
        String schoolType=getSchoolVo.getType().toString();
        List<School> pageInfo;
        List<Object> schoolTypes=Arrays.asList("综合","工科","财经","农业","林业","医药","师范","体育","政法","民族","语言"
                ,"艺术");
        if (!StringUtil.isEmpty(getSchoolVo.getType())&&schoolType.equals("[其他]")){
                         pageInfo = schoolService.list(new LambdaQueryWrapper<School>()
                    .in(!StringUtil.isEmpty(majorCodeList), School::getCode, majorCodeList)
                    .in(!StringUtil.isEmpty(codeList), School::getCode, codeList)
                    .notIn(School::getSchoolType, schoolTypes)
                    .like(!StringUtil.isEmpty(getSchoolVo.getSchool()), School::getSchoolName, getSchoolVo.getSchool())
                    .eq(!StringUtil.isEmpty(getSchoolVo.getBatch()), School::getBatch, getSchoolVo.getBatch())
                    .eq(getSchoolVo.getMajorType()!=null, School::getType, getSchoolVo.getMajorType())
//                    .ge(!StringUtil.isEmpty(getSchoolVo.getMinfraction()), School::getProposedScore, getSchoolVo.getMinfraction())
//                    .le(!StringUtil.isEmpty(getSchoolVo.getMaxfraction()), School::getProposedScore, getSchoolVo.getMaxfraction())
//                    .ge(!StringUtil.isEmpty(getSchoolVo.getMaxranking()), School::getProposedwc, getSchoolVo.getMaxranking())
//                    .le(!StringUtil.isEmpty(getSchoolVo.getMinranking()), School::getProposedwc, getSchoolVo.getMinranking())
            );
        }else{
                         pageInfo = schoolService.list(new LambdaQueryWrapper<School>()
                    .in(!StringUtil.isEmpty(majorCodeList), School::getCode, majorCodeList)
                    .in(!StringUtil.isEmpty(codeList), School::getCode, codeList)
                    .in(!StringUtil.isEmpty(getSchoolVo.getType()), School::getSchoolType, getSchoolVo.getType())
                    .like(!StringUtil.isEmpty(getSchoolVo.getSchool()), School::getSchoolName, getSchoolVo.getSchool())
                    .eq(!StringUtil.isEmpty(getSchoolVo.getBatch()), School::getBatch, getSchoolVo.getBatch())
                    .eq(getSchoolVo.getMajorType()!=null, School::getType, getSchoolVo.getMajorType())
//                    .ge(!StringUtil.isEmpty(getSchoolVo.getMinfraction()), School::getProposedScore, getSchoolVo.getMinfraction())
//                    .le(!StringUtil.isEmpty(getSchoolVo.getMaxfraction()), School::getProposedScore, getSchoolVo.getMaxfraction())
//                    .ge(!StringUtil.isEmpty(getSchoolVo.getMaxranking()), School::getProposedwc, getSchoolVo.getMaxranking())
//                    .le(!StringUtil.isEmpty(getSchoolVo.getMinranking()), School::getProposedwc, getSchoolVo.getMinranking())
                         );
        }
        List<School> relust=schoolService.list(new LambdaQueryWrapper<School>()
                .eq(School::getBatch,getSchoolVo.getBatch())
                .eq(getSchoolVo.getMajorType()!=null, School::getType, getSchoolVo.getMajorType())
//                .ge(!StringUtil.isEmpty(getSchoolVo.getMinfraction()), School::getProposedScore, getSchoolVo.getMinfraction())
//                .le(!StringUtil.isEmpty(getSchoolVo.getMaxfraction()), School::getProposedScore, getSchoolVo.getMaxfraction())
//                .ge(!StringUtil.isEmpty(getSchoolVo.getMaxranking()), School::getProposedwc, getSchoolVo.getMaxranking())
//                .le(!StringUtil.isEmpty(getSchoolVo.getMinranking()), School::getProposedwc, getSchoolVo.getMinranking())
                .orderByAsc(School::getProposedwc)
        );
        relust.forEach(i->{
            pageInfo.forEach(p->{
                if (p.getId().equals(i.getId())){
                    i.setColor(1);
                }
            });
        });
        return R.ok(relust);
    }


    @PostMapping("/getSchools")
    public R getSchools(@RequestBody GetSchoolVo getSchoolVo) {
        if (!StringUtil.isEmpty(getSchoolVo.getMaxranking()) && !StringUtil.isEmpty(getSchoolVo.getMinranking())) {
            getSchoolVo.setMaxfraction(null);
            getSchoolVo.setMinfraction(null);
        }
        List<School> pageInfo;
            pageInfo = schoolService.list(new LambdaQueryWrapper<School>()
                    .eq(!StringUtil.isEmpty(getSchoolVo.getBatch()), School::getBatch, getSchoolVo.getBatch())
                    .eq(getSchoolVo.getMajorType()!=null, School::getType, getSchoolVo.getMajorType())
//                    .ge(!StringUtil.isEmpty(getSchoolVo.getMinfraction()), School::getProposedScore, getSchoolVo.getMinfraction())
//                    .le(!StringUtil.isEmpty(getSchoolVo.getMaxfraction()), School::getProposedScore, getSchoolVo.getMaxfraction())
//                    .ge(!StringUtil.isEmpty(getSchoolVo.getMaxranking()), School::getProposedwc, getSchoolVo.getMaxranking())
//                    .le(!StringUtil.isEmpty(getSchoolVo.getMinranking()), School::getProposedwc, getSchoolVo.getMinranking())
                    .orderByAsc(School::getProposedwc)

            );
        //统计分页后的学校编号
//        if (!getSchoolVo.getBatch().equals("提前批A段") && !getSchoolVo.getBatch().equals("提前批B段") && !getSchoolVo.getBatch().equals("提前批C段") && !getSchoolVo.getBatch().equals("提前批专科") && !getSchoolVo.getBatch().equals("一批特殊") && !getSchoolVo.getBatch().equals("二批特殊")) {
//            if (!StringUtil.isEmpty(getSchoolVo.getRanking())) {
//                for (School s : pageInfo) {
//                    if (s.getProposedwc() <= (Integer.parseInt(getSchoolVo.getRanking()) * 1.1)) {
//                        s.setSprint("冲");
//                    } else {
//                        if (getSchoolVo.getBatch().equals("本科二批")) {
//                            if ((s.getProposedwc() > (Integer.parseInt(getSchoolVo.getRanking()) * 1.1)) && (s.getProposedwc() <= (Integer.parseInt(getSchoolVo.getRanking()) * 1.4))) {
//                                s.setSprint("稳");
//                            } else if (s.getProposedwc() > (Integer.parseInt(getSchoolVo.getRanking()) * 1.4)) {
//                                s.setSprint("保");
//                            }
//                        } else {
//                            if ((s.getProposedwc() > (Integer.parseInt(getSchoolVo.getRanking()) * 1.1)) && (s.getProposedwc() <= (Integer.parseInt(getSchoolVo.getRanking()) * 1.6))) {
//                                s.setSprint("稳");
//                            } else if (s.getProposedwc() > (Integer.parseInt(getSchoolVo.getRanking()) * 1.6)) {
//                                s.setSprint("保");
//                            }
//                        }
//                    }
//                }
//            } else if (StringUtil.isEmpty(getSchoolVo.getRanking())&&!StringUtil.isEmpty(getSchoolVo.getFraction())) {
//                String ranking = "";
//                if (getSchoolVo.getMajorType() == 1) {
//                    List<SysDict> km = sysDictService.list(new LambdaQueryWrapper<SysDict>().
//                            eq(SysDict::getDictType, "rankingli"));
//                    for (SysDict sysDict : km) {
//                        if (sysDict.getDictName().equals(getSchoolVo.getFraction())) {
//                            ranking = String.valueOf(sysDict.getDictValue());
//                        }
//                    }
//                } else if (getSchoolVo.getMajorType() == 2) {
//                    List<SysDict> km = sysDictService.list(new LambdaQueryWrapper<SysDict>().
//                            eq(SysDict::getDictType, "rankingwen"));
//                    for (SysDict sysDict : km) {
//                        if (sysDict.getDictName().equals(getSchoolVo.getFraction())) {
//                            ranking = String.valueOf(sysDict.getDictValue());
//                        }
//                    }
//                }
//                for (School s : pageInfo) {
//                    if (s.getProposedwc() <= (Integer.parseInt(ranking) * 1.1)) {
//                        s.setSprint("冲");
//                    } else {
//                        if (getSchoolVo.getBatch().equals("本科二批")) {
//                            if ((s.getProposedwc() > (Integer.parseInt(ranking) * 1.1)) && (s.getProposedwc() <= (Integer.parseInt(ranking) * 1.4))) {
//                                s.setSprint("稳");
//                            } else if (s.getProposedwc() > (Integer.parseInt(ranking) * 1.4)) {
//                                s.setSprint("保");
//                            }
//                        } else {
//                            if ((s.getProposedwc() > (Integer.parseInt(ranking) * 1.1)) && (s.getProposedwc() <= (Integer.parseInt(ranking) * 1.6))) {
//                                s.setSprint("稳");
//                            } else if (s.getProposedwc() > (Integer.parseInt(ranking) * 1.6)) {
//                                s.setSprint("保");
//                            }
//                        }
//                    }
//                }
//            }
//        }
        return R.ok(pageInfo);
    }


    /**
     * 获取院校录取概率
     * @param school
     * @param precedence
     */
    private void getSchoolProbability(School school, Integer precedence, String batch) {
        Map<String,String> probabilityMap = ProbabilityUtils.getOldProbability(school.getProposedwc(), precedence, batch);
        if(StringUtils.hasText(probabilityMap.get("probability"))){
            school.setProbability(probabilityMap.get("probability"));
            school.setProbabilityName(probabilityMap.get("probabilityName"));
        }
    }

    /**
     * 获取专业录取概率
     *
     * @param major
     * @param precedence
     */
    private void getMajorProbability(Major major, Integer precedence, String batch) {
        Map<String,String> probabilityMap = ProbabilityUtils.getOldProbability(major.getMajorWeici(), precedence, batch);
        if(StringUtils.hasText(probabilityMap.get("probability"))){
            major.setProbability(probabilityMap.get("probability"));
            major.setProbabilityName(probabilityMap.get("probabilityName"));
        }
    }
}
